<!DOCTYPE html>
<html lang="zh_CN" xmlns:th="http://www.thymeleaf.org"
	  th:with="title='博客管理',active='userinfo',hasEditor=true"
	  xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<!-- head 头部-->
<head th:replace="web/common/fragment::head(${title},null,'')"></head>
<body>

<div th:replace="web/layout/header::header(${active})"></div>
<!--	main	-->
<div class="fly-main">
	<div class="user-center"  th:if="${session.sessionUser!=null}"  th:with="loginUser=${session.sessionUser}">
		<div class="layui-row">
			<div class="layui-col-md2 site-tree">
				<div th:include="web/view/center/template::siteTree('blogManage')"></div>
			</div>
			<div class="layui-col-md10 site-content">
				<table class="layui-table" id="blog-table" lay-filter="blog-table"></table>
			</div>

		</div>
		<!--site tree-->
		<!--<div th:replace="web/view/center/template::siteTree('blogManage')"></div>
		<div class="site-content">
		&lt;!&ndash;<div class="fly-none">没有权限</div>&ndash;&gt;
			<table class="layui-table" id="blog-table" lay-filter="blog-table"></table>
		</div>-->
	</div>


</div>
<!--	main end	-->
<!--	底部版权		-->
<div th:replace="web/layout/footer::footer"></div>
<!--	搜索		-->
<div th:replace="web/layout/common::pop-search"></div>
<!--	右边工具栏	-->
<div th:replace="web/layout/common::right-bar"></div>
<!--	引入JS	-->
<div th:replace="web/common/fragment::js"></div>
<!-- 表格操作列 -->
<script type="text/html" id="table-bar">
	<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>修改</a>
	<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del" value="{{d.blogId}}">
		<i class="layui-icon layui-icon-delete"></i>删除</a>
</script>
<script th:inline="javascript">
	layui.use(['layer', 'form','table','util'], function(){
		var form = layui.form;
		var $ = layui.jquery;
		var layer = layui.layer;
		var table = layui.table;
		var util = layui.util;

		//渲染表格
		var tableIns = table.render({
			elem: '#blog-table',
			url: '/blog/list',
			page : true,
			loading : true,
			limit : 10,
			limits : [ 10, 20, 50, 100 ],
			response:{
				countName: 'total'
			},
			cols: [
				[
					{type: 'numbers'},
					{field: 'blogTitle',width:360, title: '文章名',templet: function (d) {
							return '<a href="/blog/'+ d.blogId +'" target="_blank" style="text-decoration: underline">'+d.blogTitle+'</a>';
						}},
					/*{field: 'catalogName',width:140, sort: true, title: '文章板块',templet: function (d) {
							return d.catalog.catalogName;
						}},*/
					/*{field: 'postType',width:100,title: '文章类型',templet:'#data-table-type'},*/
					{field: 'commentCount',width:100,sort:true, title: '评论',templet:function (d) {
							return d.commentCount==null?'0':d.commentCount;
						}},
					{field: 'clickCount',width:80,sort:true, title: '点击'},
					{
						field: 'createTime',width:160, sort: true, templet: function (d) {
							return util.toDateString(d.createTime);
						}, title: '发布时间'
					},
					{align: 'center', toolbar: '#table-bar', title: '编辑'}
				]
			]
		});
		// 工具条点击事件
		table.on('tool(blog-table)', function (obj) {
			var data = obj.data;
			if (obj.event === 'edit') { //修改
				window.location.href = '/center/blogPublish?blogId=' + data.blogId;
			}else if (obj.event === 'del') {
				layer.confirm('确定要删除此博文吗？博文下的评论也会被删掉', {shade: .1}, function () {
					B.post({
						url:'/blog/del',
						data: {id:data.blogId},
						loading: true,
						success: function (res) {
							if (res.success) {
								B.info(res.msg);
								tableIns.reload({},'data');// 重载表格
							}else{
								B.error(res.msg);
							}
						}
					})
				});

			}
		});
	})
</script>
<div th:replace="web/common/fragment::post"></div>

</body>
</html>
